import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'library_books_widget.dart';
import 'favorite_library_page.dart';

class SettingPage extends StatefulWidget {
  const SettingPage({super.key});

  @override
  State<SettingPage> createState() => _SettingPageState();
}

class _SettingPageState extends State<SettingPage> {
  var sidebarSelectedIndex = 0;
  @override
  Widget build(BuildContext context) {
    Widget page;
    switch (sidebarSelectedIndex) {
      case 0:
        page = LibraryBooksWidget();
        break;
      case 1:
        page = FavoriteLibraryPage();
        break;
      default:
        throw UnimplementedError('没有组件： $sidebarSelectedIndex');
    }
    return LayoutBuilder(
      builder: (context, constraints) {
        return Scaffold(
          body: Row(
            children: [
              SafeArea(
                child: Container(
                  decoration: BoxDecoration(
                    border: Border(
                      right: BorderSide(
                        width: 2,
                        color: Color.fromRGBO(0, 0, 0, 0.1),
                      ),
                    ),
                  ),
                  child: NavigationRail(
                    extended: constraints.maxWidth > 600,
                    destinations: [
                      NavigationRailDestination(
                        icon: Icon(Icons.library_books),
                        label: Text('单词'),
                      ),
                      NavigationRailDestination(
                        icon: Icon(Icons.favorite),
                        label: Text('喜欢'),
                      ),
                    ],
                    selectedIndex: sidebarSelectedIndex,
                    onDestinationSelected: (value) => {
                      setState(() {
                        sidebarSelectedIndex = value;
                      }),
                    },
                  ),
                ),
              ),
              ChangeNotifierProvider(
                create: (context) => LibraryBooksState(),
                child: Expanded(
                  child: Container(
                    color: Theme.of(context).colorScheme.primaryContainer,
                    child: page,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }
}
